package(default_visibility = ["//visibility:public"])

load("//def:ts.bzl", "jasmine_node_test", "rollup_bundle", "ts_library")

ts_library(
    name = "api",
    srcs = glob(["api/**/*.ts"]),
)

ts_library(
    name = "common",
    srcs = glob(["common/*.ts"]),
    deps = [
        ":api",
        "@npm//moment",
    ],
)

ts_library(
    name = "histogram",
    srcs = glob(["prow/histogram.ts"]),
    deps = [
        ":api",
    ],
)

ts_library(
    name = "prow",
    srcs = glob(
        ["prow/*.ts"],
        exclude = ["prow/histogram*.ts"],
    ) + ["vendor.d.ts"],
    deps = [
        ":api",
        ":common",
        ":histogram",
        "@npm//@types/gtag.js",
        "@npm//moment",
    ],
)

ts_library(
    name = "prow_test_lib",
    srcs = ["prow/histogram_test.ts"],
    deps = [
        ":histogram",
        "@npm//@types/jasmine",
    ],
)

jasmine_node_test(
    name = "prow_test",
    srcs = [
        ":prow_test_lib",
    ],
    templated_args = ["--bazel_patch_module_resolver"],
    deps = [
        "@npm//jasmine",
    ],
)

rollup_bundle(
    name = "prow_bundle",
    entry_point = ":prow/prow.ts",
    deps = [
        ":prow",
        "@npm//moment",
    ],
)

ts_library(
    name = "plugin_help",
    srcs = glob(["plugin-help/*.ts"]) + ["vendor.d.ts"],
    deps = [
        ":api",
        ":common",
    ],
)

rollup_bundle(
    name = "plugin_help_bundle",
    entry_point = ":plugin-help/plugin-help.ts",
    deps = [
        ":plugin_help",
        "@npm//code-prettify",
        "@npm//dialog-polyfill",
    ],
)

ts_library(
    name = "pr",
    srcs = glob(["pr/*.ts"]) + ["vendor.d.ts"],
    deps = [
        ":api",
        ":common",
    ],
)

rollup_bundle(
    name = "pr_bundle",
    entry_point = "pr/pr.ts",
    deps = [
        ":pr",
        "@npm//dialog-polyfill",
        "@npm//moment",
    ],
)

ts_library(
    name = "tide",
    srcs = glob(["tide/*.ts"]),
    deps = [
        ":api",
        ":common",
    ],
)

rollup_bundle(
    name = "tide_bundle",
    entry_point = ":tide/tide.ts",
    deps = [
        ":tide",
        "@npm//moment",
    ],
)

ts_library(
    name = "tide_history",
    srcs = glob(["tide-history/*.ts"]),
    deps = [
        ":api",
        ":common",
        "@npm//moment",
    ],
)

rollup_bundle(
    name = "tide_history_bundle",
    entry_point = ":tide-history/tide-history.ts",
    deps = [
        ":tide_history",
        "@npm//moment",
    ],
)

ts_library(
    name = "command_help",
    srcs = glob(["command-help/*.ts"]) + ["vendor.d.ts"],
    deps = [
        ":api",
        ":common",
    ],
)

rollup_bundle(
    name = "command_help_bundle",
    entry_point = ":command-help/command-help.ts",
    deps = [
        ":command_help",
        "@npm//dialog-polyfill",
    ],
)

ts_library(
    name = "spyglass",
    srcs = ["spyglass/spyglass.ts"],
    deps = [
        ":spyglass_common",
    ],
)

ts_library(
    name = "spyglass_lens",
    srcs = ["spyglass/lens.ts"],
    deps = [
        ":common",
        ":spyglass_common",
    ],
)

ts_library(
    name = "spyglass_common",
    srcs = ["spyglass/common.ts"],
)

rollup_bundle(
    name = "spyglass_bundle",
    entry_point = ":spyglass/spyglass.ts",
    deps = [
        ":spyglass",
        ":spyglass_common",
    ],
)

rollup_bundle(
    name = "spyglass_lens_bundle",
    entry_point = ":spyglass/lens.ts",
    deps = [
        ":spyglass_common",
        ":spyglass_lens",
    ],
)

test_suite(
    name = "unit_tests",
    tests = [
        ":prow_test",
    ],
)

genrule(
    name = "labels_css",
    srcs = [
        "//label_sync:labels.css.tmpl",
        "//label_sync:labels.yaml",
    ],
    outs = ["labels.css"],
    cmd = "$(location //label_sync) --action=css --css-template=$(location //label_sync:labels.css.tmpl) --config=$(location //label_sync:labels.yaml) --css-output=$@",
    tools = [
        "//label_sync",
    ],
)

filegroup(
    name = "resources",
    srcs = glob(
        ["**/*"],
        exclude = ["**/*.js"],
    ) + glob(["extensions/*.js"]) + [":labels_css"],
)

filegroup(
    name = "all-scripts",
    srcs = [
        ":command_help_bundle",
        ":plugin_help_bundle",
        ":pr_bundle",
        ":prow_bundle",
        ":spyglass_bundle",
        ":spyglass_lens_bundle",
        ":tide_bundle",
        ":tide_history_bundle",
    ],
)

filegroup(
    name = "static",
    srcs = [
        ":all-scripts",
        ":resources",
    ],
)

filegroup(
    name = "package-srcs",
    srcs = glob(["**"]),
    tags = ["automanaged"],
    visibility = ["//visibility:private"],
)

filegroup(
    name = "all-srcs",
    srcs = [":package-srcs"],
    tags = ["automanaged"],
    visibility = ["//visibility:public"],
)
